﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;
using System.Collections.Generic;

namespace HZ.DrugTrade.Web.Hospitals.Procurement
{
    public partial class MyGoodsList : BasePage
    {
        public MyGoodsList()
        {
            this.ModuleNo = Module.产品库管理.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindGridView();
            }
        }

        /// <summary>
        /// 执行筛选
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            BindGridView();
        }

        /// <summary>
        /// 绑定列表
        /// </summary>
        private void BindGridView()
        {
            //构造查询条件
            Model.Query.CustomGoods where = new HZ.DrugTrade.Model.Query.CustomGoods();


            switch (dllAuditStatusMS.SelectedValue)
            {
                case "0":
                    where.AuditStatusMS = null;
                    break;
                case "1":
                    where.AuditStatusMS = 1;
                    break;
                case "2":
                    where.AuditStatusMS = 2;
                    break;
                case "3":
                    where.AuditStatusMS = 3;
                    break;
                case "4":
                    where.AuditStatusMS = 4;
                    break;
            }
            switch (dllAuditStatus.SelectedValue)
            {
                case "0":
                    where.AuditStatus = null;
                    break;
                case "1":
                    where.AuditStatus = 1;
                    break;
                case "2":
                    where.AuditStatus = 2;
                    break;
                case "3":
                    where.AuditStatus = 3;
                    break;
                case "4":
                    where.AuditStatus = 4;
                    break;
            }
            where.HospitalID = CurrentAccount.GetUser().Org.OrgID; //设置当前登录用户的医疗机构ID（必选项）
            where.GoodsName = txtGoodsName.Text.Trim();
            where.Outlookc = txtOutLook.Text.Trim();
            where.Material = txtMaterial.Text.Trim() ;
            where.Unit = txtUnit.Text.Trim();
            where.CompanyName = txtProduceCompany_SC.Text.Trim();
            where.GoodsName = txtGoodsName.Text.Trim();
            where.SortFields = " AddTime Desc";

            int totalCount;
            IBLL_CustomGoods cstCtrl = Factory.BLL_CustomGoods();
            IList<HZ.DrugTrade.Model.View.CustomGoods> cstList = cstCtrl.GetCustomGoodsByWhere(where, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;

            this.gvwBidDrug.DataSource = cstList;
            this.gvwBidDrug.DataBind();

        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            BindGridView();
        }

        /// <summary>
        /// 格式化审核状态
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected string FormatAuditStatus(object obj)
        {
            string status = "未知";
            if (obj != null)
            {
                switch  (Convert.ToInt16(obj))
                {
                    case 1: status = "未审核";
                        break;
                    case 2: status =  "需修改";
                        break;
                    case 3: status = "<font color=green>已通过</font>";
                        break;
                    case 4: status = "<font color=red>已拒绝</font>";
                        break;
                }
            }
            return status;
        }
        /// <summary>
        /// 格式化审核状态
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected string FormatSubmitStatus(object obj)
        {
            string status = "未知";
            if (obj != null)
            {
                switch (Convert.ToInt16(obj))
                {
                    case 0: status = "未提交";
                        break;
                    case 1: status = "已提交";
                        break;
                    case 2: status = "已拒绝可修改";
                        break;
                }
            }
            return status;
        }
        /// <summary>
        /// gridview命令事件响应
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwBidDrug_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //删除
            if (e.CommandName == "Del")
            {
                string strID = e.CommandArgument.ToString();
                CustomGoods model = new CustomGoods(){ ID = Convert.ToInt32( strID) };

                IBLL_CustomGoods cstCtrl = Factory.BLL_CustomGoods();
                int flag = cstCtrl.DeleteCustomGoods(model);
                if (flag == 0)
                {
                    HZ.Web.WebUtil.Alert("删除失败！",this);
                }
                if (flag == 1)
                {
                    HZ.Web.WebUtil.Alert("删除成功！",this);

                    //刷新列表
                    BindGridView();
                }
            }
        }

    }
}
